package com.ruoyi.supervise.service.impl.decisupport;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.supervise.domain.decisupport.ConstructionProject;
import com.ruoyi.supervise.domain.decisupport.MunicipalEngineering;
import com.ruoyi.supervise.domain.decisupport.MyBigDataAllProHoursPro;
import com.ruoyi.supervise.domain.decisupport.MyBigDataProZS;
import com.ruoyi.supervise.mapper.decisupport.MyBigDataProZSMapper;
import com.ruoyi.supervise.service.decisupport.MyBigDataProZSService;
import com.ruoyi.supervise.util.DateUtils;

@Service
@DataSource(value = DataSourceType.SLAVE)
public class MyBigDataProZSServiceImpl implements MyBigDataProZSService{

    @Autowired
    private MyBigDataProZSMapper myBigDataProZSMapper;

	@Override
	public List<MyBigDataProZS> selectAllProMonthZS(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataProZSMapper.selectAllProMonthZS(bd);
	}

	@Override
	public List<MyBigDataProZS> selectAllProMonthZSData(MyBigDataAllProHoursPro bd) {
		try {
			//获取全省开工月度趋势走势图数据
			DateUtils du=new DateUtils();
			List<String> monthStr=du.getMonthBetween(bd.getTimeNowBegin(), bd.getTimeNowEnd());
			List<MyBigDataProZS> allProvinceStartProList=new ArrayList<MyBigDataProZS>();
			for(String s:monthStr)
			{
				MyBigDataProZS allProvinceStartPro=new MyBigDataProZS();
				String year=s.substring(0, s.indexOf("-"));
				String month=s.substring(year.length()+1, s.length());
				allProvinceStartPro.setYear(Integer.parseInt(year));
				allProvinceStartPro.setMonth(Integer.parseInt(month));
				allProvinceStartPro.setCompare("0");
				allProvinceStartPro.setTotal("0");
				allProvinceStartProList.add(allProvinceStartPro);
			}
			List<MyBigDataProZS> pspList=myBigDataProZSMapper.selectAllProMonthZS(bd);
			for(MyBigDataProZS m:allProvinceStartProList)
			{
				for(MyBigDataProZS pspl:pspList)
				{
					if(m.getMonth()==pspl.getMonth() && m.getYear()==pspl.getYear())
					{

						BigDecimal bdTotal = new BigDecimal(pspl.getTotal());  
						m.setCompare(pspl.getCompare());
						m.setTotal(bdTotal.toPlainString());
					}
				}
			}
			System.out.println(allProvinceStartProList);
			return allProvinceStartProList;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<MyBigDataProZS> selectAllFJMonthZS(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataProZSMapper.selectAllFJMonthZS(bd);
	}

	@Override
	public List<MyBigDataProZS> selectAllFJMonthZSData(MyBigDataAllProHoursPro bd) {
		DateUtils du=new DateUtils();
		try {
			List<String> monthStr=du.getMonthBetween(bd.getTimeNowBegin(), bd.getTimeNowEnd());
			List<MyBigDataProZS> allProvinceFJStartProList=new ArrayList<MyBigDataProZS>();
			for(String s:monthStr)
			{
				MyBigDataProZS allProvinceStartPro=new MyBigDataProZS();
				String year=s.substring(0, s.indexOf("-"));
				String month=s.substring(year.length()+1, s.length());
				allProvinceStartPro.setYear(Integer.parseInt(year));
				allProvinceStartPro.setMonth(Integer.parseInt(month));
				allProvinceStartPro.setCompare("0");
				allProvinceStartPro.setTotal("0");
				allProvinceFJStartProList.add(allProvinceStartPro);
			}
			List<MyBigDataProZS> psfjpList=myBigDataProZSMapper.selectAllFJMonthZS(bd);
			for(MyBigDataProZS m:allProvinceFJStartProList)
			{
				for(MyBigDataProZS pspl:psfjpList)
				{
					if(m.getMonth()==pspl.getMonth() && m.getYear()==pspl.getYear())
					{
						BigDecimal bdTotal = new BigDecimal(pspl.getTotal());  
						m.setCompare(pspl.getCompare());
						m.setTotal(bdTotal.toPlainString());
					}
				}
			}
			return allProvinceFJStartProList;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<MyBigDataProZS> selectAllProNumMonthZS(ConstructionProject cp) {
		// TODO Auto-generated method stub
		return myBigDataProZSMapper.selectAllProNumMonthZS(cp);
	}

	@Override
	public List<MyBigDataProZS> selectAllProNumCPMonthZS(ConstructionProject cp) {
		DateUtils du=new DateUtils();
		try {
			List<String> monthStr=du.getMonthBetween(cp.getTimeNowBegin(), cp.getTimeNowEnd());
			List<MyBigDataProZS> allProvinceStartProNumList=new ArrayList<MyBigDataProZS>();
			for(String s:monthStr)
			{
				MyBigDataProZS allProvinceStartPro=new MyBigDataProZS();
				String year=s.substring(0, s.indexOf("-"));
				String month=s.substring(year.length()+1, s.length());
				allProvinceStartPro.setYear(Integer.parseInt(year));
				allProvinceStartPro.setMonth(Integer.parseInt(month));
				allProvinceStartPro.setCompare("0");
				allProvinceStartPro.setTotal("0");
				allProvinceStartProNumList.add(allProvinceStartPro);
			}
			List<MyBigDataProZS> allProNumList=myBigDataProZSMapper.selectAllProNumMonthZS(cp);
			for(MyBigDataProZS m:allProvinceStartProNumList)
			{
				for(MyBigDataProZS apnl:allProNumList)
				{
					if(m.getMonth()==apnl.getMonth() && m.getYear()==apnl.getYear())
					{
						BigDecimal bdTotal = new BigDecimal(apnl.getTotal());  
						m.setCompare(apnl.getCompare());
						m.setTotal(bdTotal.toPlainString());
					}
				}
			}
			return allProvinceStartProNumList;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<MyBigDataProZS> selectAllProMoneyMonthZS(ConstructionProject cp) {
		// TODO Auto-generated method stub
		return myBigDataProZSMapper.selectAllProMoneyMonthZS(cp);
	}

	@Override
	public List<MyBigDataProZS> selectAllProMoneyCPMonthZS(ConstructionProject cp) {
		DateUtils du=new DateUtils();
		try {
			List<String> monthStr=du.getMonthBetween(cp.getTimeNowBegin(), cp.getTimeNowEnd());
			List<MyBigDataProZS> allProvinceStartProMoneyList=new ArrayList<MyBigDataProZS>();
			for(String s:monthStr)
			{
				MyBigDataProZS allProvinceStartPro=new MyBigDataProZS();
				String year=s.substring(0, s.indexOf("-"));
				String month=s.substring(year.length()+1, s.length());
				allProvinceStartPro.setYear(Integer.parseInt(year));
				allProvinceStartPro.setMonth(Integer.parseInt(month));
				allProvinceStartPro.setCompare("0");
				allProvinceStartPro.setTotal("0");
				allProvinceStartProMoneyList.add(allProvinceStartPro);
			}
			List<MyBigDataProZS> allProMoneyList=myBigDataProZSMapper.selectAllProMoneyMonthZS(cp);
			for(MyBigDataProZS m:allProvinceStartProMoneyList)
			{
				for(MyBigDataProZS apml:allProMoneyList)
				{
					if(m.getMonth()==apml.getMonth() && m.getYear()==apml.getYear())
					{
						BigDecimal bdTotal = new BigDecimal(apml.getTotal());  
						m.setCompare(apml.getCompare());
						m.setTotal(bdTotal.toPlainString());
					}
				}
			}
			return allProvinceStartProMoneyList;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<MyBigDataProZS> selectMEProNumMonthZS(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return myBigDataProZSMapper.selectMEProNumMonthZS(me);
	}

	@Override
	public List<MyBigDataProZS> selectMEProNumMonthZSData(MunicipalEngineering me) {
		DateUtils du=new DateUtils();
		try {
			List<String> monthStr=du.getMonthBetween(me.getTimeNowBegin(), me.getTimeNowEnd());
			List<MyBigDataProZS> allProvinceMEStartProNumList=new ArrayList<MyBigDataProZS>();
			for(String s:monthStr)
			{
				MyBigDataProZS allProvinceMEStartPro=new MyBigDataProZS();
				String year=s.substring(0, s.indexOf("-"));
				String month=s.substring(year.length()+1, s.length());
				allProvinceMEStartPro.setYear(Integer.parseInt(year));
				allProvinceMEStartPro.setMonth(Integer.parseInt(month));
				allProvinceMEStartPro.setCompare("0");
				allProvinceMEStartPro.setTotal("0");
				allProvinceMEStartProNumList.add(allProvinceMEStartPro);
			}
			List<MyBigDataProZS> allProMENumList=myBigDataProZSMapper.selectMEProNumMonthZS(me);
			for(MyBigDataProZS m:allProvinceMEStartProNumList)
			{
				for(MyBigDataProZS apnl:allProMENumList)
				{
					if(m.getMonth()==apnl.getMonth() && m.getYear()==apnl.getYear())
					{
						BigDecimal bdTotal = new BigDecimal(apnl.getTotal());  
						m.setCompare(apnl.getCompare());
						m.setTotal(bdTotal.toPlainString());
					}
				}
			}
			return allProvinceMEStartProNumList;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<MyBigDataProZS> selectMEProMoneyMonthZS(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return myBigDataProZSMapper.selectMEProMoneyMonthZS(me);
	}

	@Override
	public List<MyBigDataProZS> selectMEProMoneyMonthZSData(MunicipalEngineering me) {
		DateUtils du=new DateUtils();
		try {
			List<String> monthStr=du.getMonthBetween(me.getTimeNowBegin(), me.getTimeNowEnd());
			List<MyBigDataProZS> allProvinceMEStartProMoneyList=new ArrayList<MyBigDataProZS>();
			for(String s:monthStr)
			{
				MyBigDataProZS allProvinceMEStartPro=new MyBigDataProZS();
				String year=s.substring(0, s.indexOf("-"));
				String month=s.substring(year.length()+1, s.length());
				allProvinceMEStartPro.setYear(Integer.parseInt(year));
				allProvinceMEStartPro.setMonth(Integer.parseInt(month));
				allProvinceMEStartPro.setCompare("0");
				allProvinceMEStartPro.setTotal("0");
				allProvinceMEStartProMoneyList.add(allProvinceMEStartPro);
			}
			List<MyBigDataProZS> allProMEMoneyList=myBigDataProZSMapper.selectMEProMoneyMonthZS(me);
			for(MyBigDataProZS m:allProvinceMEStartProMoneyList)
			{
				for(MyBigDataProZS apml:allProMEMoneyList)
				{
					if(m.getMonth()==apml.getMonth() && m.getYear()==apml.getYear())
					{
						BigDecimal bdTotal = new BigDecimal(apml.getTotal());  
						m.setCompare(apml.getCompare());
						m.setTotal(bdTotal.toPlainString());
					}
				}
			}
			return allProvinceMEStartProMoneyList;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
